package com.www.applyword.ui.my;

import android.content.Intent;
import android.view.View;

import com.allen.library.SuperTextView;
import com.tencent.imsdk.TIMCallBack;
import com.tencent.imsdk.TIMManager;
import com.tencent.qcloud.tim.uikit.TUIKit;
import com.www.applyword.R;
import com.www.applyword.base.BaseActivity;
import com.www.applyword.main.LoginActivity;
import com.www.applyword.utils.SPUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * author : huang
 * date   : 2019/10/22 0022 15:45
 * version: 1.0
 * @author Administrator
 */
public class SettingActivity extends BaseActivity {
    @BindView(R.id.sv_set_login)
    SuperTextView svSetLogin;
    @BindView(R.id.sv_set_pay)
    SuperTextView svSetPay;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.settting_activity);
        setTitle("设置");

    }

    @Override
    protected void loadData() {

    }


    @OnClick({R.id.sv_set_login, R.id.sv_set_pay,R.id.sb_login_out})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.sv_set_login:
                startActivity(new Intent(this, ResetPasswordActivity.class));
                break;
            case R.id.sv_set_pay:
                startActivity(new Intent(this, ResetPayActivity.class));
                break;
            case R.id.sb_login_out:
                //登出
                TIMManager.getInstance().logout(new TIMCallBack() {
                    @Override
                    public void onError(int code, String desc) {
                        //错误码 code 和错误描述 desc，可用于定位请求失败原因
                        //错误码 code 列表请参见错误码表
                       // Log.d(tag, "logout failed. code: " + code + " errmsg: " + desc);
                      //  Utils.showToastSafe("logout failed. code: " + code + " errmsg: " + desc);
                        if (code == 6014){
                            SPUtil.put("login", false);
                            SPUtil.put("userInfo_state", 0);
                            Intent intent = new Intent(SettingActivity.this, LoginActivity.class);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            startActivity(intent);
                            finish();
                        }
                    }

                    @Override
                    public void onSuccess() {
                        SPUtil.put("login", false);
                        TUIKit.unInit();
                        Intent intent = new Intent(SettingActivity.this, LoginActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        startActivity(intent);
                        finish();
                    }
                });
                break;
                default:
        }
    }
}
